<!DOCTYPE html>
<html lang="en"  ng-app="MyAPP">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width" />
    <title>Index</title>
    <link rel="stylesheet" href="http://cdn.bootcss.com/bootstrap/3.3.2/css/bootstrap.css">
    <style type="text/css">
        body { padding-top: 30px; }
    </style>
</head>
<body>
<div class="col-md-6">
    <h6>
        <a href="http://www.cnblogs.com/rohelm/p/4033513.html">文章：http://www.cnblogs.com/rohelm/p/4033513.html</a>
    </h6>
    <form class="form-horizontal" role="form" id="custom_form" name="custom_form" novalidate>
        <div class="form-group">
            <label class="col-sm-2 control-label">多个email</label>

            <div class="col-sm-10">
                <input multiple-email name="user_email" ng-model="user.email" required class="form-control" placeholder="自定义验证，多个邮箱地址，以“；”或者“;”分割" />
                验证通过：{{custom_form.user_email.$valid}}
            </div>
        </div>
        <div class="form-group  text-center">
            <input class="btn btn-primary btn-lg" ng-disabled="custom_form.$invalid" type="submit" value="提交" />
        </div>
    </form>
</div>
</body>
</html>
<script src="http://cdn.bootcss.com/angular.js/1.3.8/angular.js" type="text/javascript"></script>
<script type="text/javascript">
    angular.module("MyAPP", []).directive('multipleEmail', [function () {
                return {
                    require: "ngModel",
                    link: function (scope, element, attr, ngModel) {
                        if (ngModel) {
                            var emailsRegexp = /^([a-z0-9!#$%&'*+\/=?^_`{|}~.-]+@[a-z0-9-]+(\.[a-z0-9-]+)*[;；]?)+$/i;
                        }
                        var customValidator = function (value) {
                            var validity = ngModel.$isEmpty(value) || emailsRegexp.test(value);
                            ngModel.$setValidity("multipleEmail", validity);
                            return validity ? value : undefined;
                        };
                        ngModel.$formatters.push(customValidator);
                        ngModel.$parsers.push(customValidator);
                    }
                };
            }]);
</script>